/*
 * 浏览器中直接使用该地址临时看下这个页面都有那些功能权限
 * https://192.168.3.7:8080/agent/xw-microservice/xw-system/v3/pool/menu/btn/list/open?code=m017
 * */
import pinia from '../plugins/pinia.js';
import { useUserInfoStore } from '../pinia/userInfo.js';

const userInfo = useUserInfoStore(pinia);

export function isBtnHasAuth(keyVal) {
  if (!keyVal) {
    return true;
  }
  keyVal = keyVal.split('&&');
  const userButtons = userInfo.userButtons;
  return keyVal.every((val) => {
    return userButtons.includes(val);
  });
}

export default function (app) {
  app.directive('auth', {
    // 当被绑定的元素插入到 DOM 中时……
    mounted(el, binding) {
      if (!isBtnHasAuth(binding.value)) {
        el.style.display = 'none';
      }
    },
  });
}
